package account;

import interceptor.InjectConnection;

import java.sql.Connection;
import java.util.List;

import utils.Var;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

/**
 * Created by IntelliJ IDEA.
 * User: Shawn
 * Date: 2009-6-2
 * Time: 21:31:27
 */
public class InfoAction {

  private Connection con;

  @InjectConnection
  public void setCon(Connection con) {
    this.con = con;
  }

  private int accountID;

  public void setAccountID(int accountID) {
    this.accountID = accountID;
  }

  public int getAccountID() {
    return accountID;
  }

  //get account list
  private List<AccountInfo> list;

  public String getAccounts() throws Exception {
    HttpSession session = ServletActionContext.getRequest().getSession();
    if (!AccountUtils.isAdmin(session)) throw new Exception("deny");
    list = Account.getAccountList(con);
    return Var.ACTION_SUCCESS;
  }

  public List<AccountInfo> getList() {
    return list;
  }

  //get account info
  private AccountInfo info;

  public String getAccountInfo() throws Exception {
    HttpSession session = ServletActionContext.getRequest().getSession();
    if (!AccountUtils.isAdmin(session)) throw new Exception("deny");
    info = accountID == -1 ? new AccountInfo() : Account.getAccountInfo(con, accountID);
    return Var.ACTION_SUCCESS;
  }

  public AccountInfo getInfo() {
    return info;
  }
}
